/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.fyx.secure.entity;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.Cacheable;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author xljan
 */
@Entity
@Table(name = "secure_group")
@XmlRootElement
@Cacheable(false)
@NamedQueries({
    @NamedQuery(name = "SecureGroup.findAll", 
        query = "SELECT s FROM SecureGroup s"),
    @NamedQuery(name = "SecureGroup.findByIdGroup", 
        query = "SELECT s FROM SecureGroup s WHERE s.idGroup = :idGroup"),
    @NamedQuery(name = "SecureGroup.findByName", 
        query = "SELECT s FROM SecureGroup s WHERE s.name = :name")})
public class SecureGroup implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @NotNull
    @Column(name = "id_group")
    private Integer idGroup;
    @Size(max = 255)
    @Column(name = "name")
    private String name;
    @ManyToMany(mappedBy = "secureGroupCollection")
    private Collection<SecureUser> secureUserCollection;
    @JoinTable(name = "secure_group_role", joinColumns = {
        @JoinColumn(name = "id_group", referencedColumnName = "id_group")}, 
            inverseJoinColumns = {
        @JoinColumn(name = "code", referencedColumnName = "code")})
    @ManyToMany
    private Collection<SecureRole> secureRoleCollection;

    public SecureGroup() {
    }

    public SecureGroup(Integer idGroup) {
        this.idGroup = idGroup;
    }

    public Integer getIdGroup() {
        return idGroup;
    }

    public void setIdGroup(Integer idGroup) {
        this.idGroup = idGroup;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @XmlTransient
    public Collection<SecureUser> getSecureUserCollection() {
        return secureUserCollection;
    }

    public void setSecureUserCollection(
            Collection<SecureUser> secureUserCollection) {
        this.secureUserCollection = secureUserCollection;
    }

    @XmlTransient
    public Collection<SecureRole> getSecureRoleCollection() {
        return secureRoleCollection;
    }

    public void setSecureRoleCollection(
            Collection<SecureRole> secureRoleCollection) {
        this.secureRoleCollection = secureRoleCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idGroup != null ? idGroup.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof SecureGroup)) {
            return false;
        }
        SecureGroup other = (SecureGroup) object;
        if ((this.idGroup == null && other.idGroup != null) || (
                this.idGroup != null && !this.idGroup.equals(other.idGroup))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.fyx.secure.entity.SecureGroup[ idGroup=" + idGroup + " ]";
    }
    
}
